#pragma once

#include "sqlite3.h"
#define SQLITEEXTENSION ".db"


class CFileManager
{
public:
	CFileManager(std::string);
	virtual ~CFileManager();
	static bool InitialGlobalResource();
	static uintptr_t FindDBFile(std::string filename);
	static bool FindAndAddDBFile(std::string filename, uintptr_t object);
	static bool RemoveDBFile(std::string filename);

	std::string GetFileName() { return mFileName; }
	std::string& GetTableName() { return mTableName; }

private:
	static bool initialed;
	static CRITICAL_SECTION mDBFilesMapLock;
	static std::map<std::string, uintptr_t> mAllDBFiles;

	std::string mFileName;
	std::string mTableName;
};

class CSQLiteHandler {
public:
	CSQLiteHandler();
	virtual ~CSQLiteHandler();

	bool OpenDB(std::string filename);
protected:
	sqlite3 *mSession;

	class SQLiteCBArg {
	public:
		SQLiteCBArg(HANDLE obj) :EventObj(obj), total(-1), values() {}

		HANDLE EventObj;
		long total;
		std::map<std::string, std::list<std::string>> values;
	};
	HANDLE mSyncObj;
};